const express = require('express');
const serverRouter = require('./router/server/');
const jwt = require('express-jwt');
const cors = require('cors');
const bodyParser = require('body-parser');

require('./db_init');

const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.use('/server', serverRouter);

app.use(function (err, req, res, next) {
    // next();
    if (err.name === 'UnauthorizedError') {
        res.status(401).send('invalid token...');
    }
});

app.use(serverRouter);

const port = 3000;
app.listen(port, function (err) {
    if (err) {
        console.log(err);
    } else {
        console.log('Server started');
    }
});
